package com.ruoyi.web.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.web.controller.xhs.dto.XhsReqDTO;
import com.ruoyi.web.service.RemoteService;
import com.ruoyi.xhs.entity.XhsSearchResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * RemoteServiceImpl
 *
 * @author Wayne Wei
 * @version 1.0
 * @date 2025/6/20
 * @description 外部接口实现类
 */
@Service
public class RemoteServiceImpl implements RemoteService {

    Logger logger = LoggerFactory.getLogger(RemoteServiceImpl.class);

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public XhsSearchResult fetchByType(XhsReqDTO request) {
        ResponseEntity<String> responseEntity;
        // 根据查询得类型组装数据
        if (request.getType().equals("01")) {
            // 发送 POST 请求
            responseEntity = restTemplate.postForEntity(
                    "http://127.0.0.1:8000/spider_some_search_note", request, String.class
            );
            logger.info("采集响应:{}", JSON.toJSONString(responseEntity));
        }
        // 通过用户URL链接获取用户所有笔记
        if (request.getType().equals("02")) {
            // 发送 POST 请求
            responseEntity = restTemplate.postForEntity(
                    "http://127.0.0.1:8000/get_user_all_notes", request, String.class
            );
            logger.info("采集响应:{}", JSON.toJSONString(responseEntity));
        }
        return null;
    }
}